<template>
  <el-dialog title="支部评定结果" v-model="openOrgResult" width="40%" class="" append-to-body>
      <div class="dialog-top-line"></div>
      <el-form ref="ReviewRef" :model="formOrgResult" :rules="orgEvaluateRules" label-width="96px">
        <el-row style="margin: 11px 0px 19px 0px;">
          <el-col :span="24">
            <el-form-item label="民主评议对象">
              <el-input v-model="formOrgResult.reviewedUserName" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="评定结果" prop="grade">
              <el-select v-model="formOrgResult.grade" placeholder="请选择评定结果" clearable :disabled="isDisabledFlag">
                <el-option
                  v-for="dict in pb_evaluate_result"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否奖励" prop="result">
              <el-select v-model="formOrgResult.result" placeholder="请选择是否奖励" clearable :disabled="isDisabledFlag">
                <el-option
                  v-for="dict in sys_rewards"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="详情" prop="details">
              <el-input v-model="formOrgResult.details" placeholder="请输入详情" type="textarea" :rows="8" :disabled="isDisabledFlag"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="dialog-bottom-line"></div>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitOrgEvalResult" v-if="!isDisabledFlag">确 定</el-button>
          <el-button @click="cancelOrgEvalResult">取 消</el-button>
        </div>
      </template>
    </el-dialog>
</template>

<script setup>
import { orgComment } from "@/api/partybuilding/Review";
const props = defineProps({
  isDisabled: {
    type: Boolean,
    default: false
  },
})
const isDisabledFlag = props.isDisabled;
const { proxy } = getCurrentInstance();
const openOrgResult = ref(false);
const emit = defineEmits(['callBack']);
const { pb_evaluate_result } = proxy.useDict("pb_evaluate_result");
const sys_rewards = ref([{label: '无奖励', value: '0'}, {label: '有奖励', value: '1'}]);

const data = reactive({
  formOrgResult: {
    reviewId: null,
    reviewedUser: null,
    reviewedUserName: null,
    grade: null,
    type: 2, //评议类型：0互评,1自评，2组织，3群众
    result: null,
    details: null
  },
  orgEvaluateRules: {
    grade: [
      { required: true, message: "评定结果不能为空", trigger: "blur" }
    ],
    result: [
      { required: true, message: "是否奖励不能为空", trigger: "blur" }
    ]
  }
});

const { formOrgResult, orgEvaluateRules } = toRefs(data);

const showOrgResult = (row) => {
  formOrgResult.value.reviewId = row.reviewId;
  formOrgResult.value.reviewedUser = row.reviewedUser;
  formOrgResult.value.reviewedUserName = row.reviewedUserName;
  if (isDisabledFlag){
    // 只读
    formOrgResult.value.grade  = row.grade?row.grade+'':'';
    formOrgResult.value.result  = row.result?row.result+'':'';
    formOrgResult.value.details  = row.details;
  }else{
    formOrgResult.value.grade  = null;
    formOrgResult.value.result  = null;
    formOrgResult.value.details  = null;
  }
  openOrgResult.value = true;
};

defineExpose({
    showOrgResult
});

// 提交支部评定
function submitOrgEvalResult() {
  proxy.$refs["ReviewRef"].validate(valid => {
    if (valid) {
      orgComment(formOrgResult.value).then(response => {
        proxy.$modal.msgSuccess("支部评定成功");  
        openOrgResult.value = false;
        emit('callBack', null);
      });
    }
  });
}

// 取消支部评定
function cancelOrgEvalResult() {
  formOrgResult.value = {};
  openOrgResult.value = false;
  emit('callBack', null);
}
</script>
<style lang="scss" scoped>
.spanUserTitle {
  height: 22px;
  background-color: rgb(255, 255, 255);
  color: rgb(51, 51, 51);
  font-size: 16px;
  text-align: left;
  font-family: PingFangSC-Regular;
}
.itemTogetherTitle {
    font-size: 14px;
    text-align: left;
    font-family: PingFangSC-Regular;
    color: rgb(153, 153, 153) !important;
    padding: 19px 59px;
}
.dialog-top-line {
  width: 100%;
  height: 1px;
  background-color: #ccc;
  position: absolute;
  left: 0px;
  top: 49px;
}
.dialog-bottom-line {
  width: 100%;
  height: 1px;
  background-color: #ccc;
  position: absolute;
  left: 0px;
  bottom: 65px;
}
</style>